<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fick.hibernate.model.*"%>
<%@ page import="com.fick.hibernate.dao.*"%>
<%@page import="com.fick.tools.SystemLogger"%>
<%@ include file="../tld/tlds.jsp"%>
<%
   Admin admins = (Admin)request.getSession().getAttribute("admin");
 %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {font-size: 12px;}
.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;

}
a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}
a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.STYLE7 {font-size: 12px;}

</style>
<script type="text/javascript" src="js/meihuaxue.js"></script>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/submit.js"></script>
<script type="text/javascript">

 function assAllDate(){
       var flag = true;
       var temp = "";
       var tmp ;
       if((document.getElementsByName("MyCheckBox").length+"")=="undefined"){
         tmp=1;
       }else{
         tmp=document.getElementsByName("MyCheckBox").length;
       }
       if(tmp==1){
         if(document.getElementsByName("MyCheckBox")[0].checked){
           flag = false;
           temp = document.getElementsByName("MyCheckBox")[0].value;
         }
       }else{
           for(var i=0;i<document.getElementsByName("MyCheckBox").length;i++){
             if(document.getElementsByName("MyCheckBox")[i].checked){
               if(temp == ""){
                 flag = false;
                 temp = document.getElementsByName("MyCheckBox")[i].value;
               }else{
                 flag = false;
                 temp = temp + "," + document.getElementsByName("MyCheckBox")[i].value;
             }
           }
         }
       }
   if(flag){
     alert("请选中一条记录");
     return false;
   }else{
      if(confirm("确定审核全部?")){
             location="/admin/managerNew.do?method=assNewsByStr&str="+temp;
      }
   }
  }
  
  
   function assAllDates(){
       var flag = true;
       var temp = "";
       var tmp ;
       if((document.getElementsByName("MyCheckBox").length+"")=="undefined"){
         tmp=1;
       }else{
         tmp=document.getElementsByName("MyCheckBox").length;
       }
       if(tmp==1){
         if(document.getElementsByName("MyCheckBox")[0].checked){
           flag = false;
           temp = document.getElementsByName("MyCheckBox")[0].value;
         }
       }else{
           for(var i=0;i<document.getElementsByName("MyCheckBox").length;i++){
             if(document.getElementsByName("MyCheckBox")[i].checked){
               if(temp == ""){
                 flag = false;
                 temp = document.getElementsByName("MyCheckBox")[i].value;
               }else{
                 flag = false;
                 temp = temp + "," + document.getElementsByName("MyCheckBox")[i].value;
             }
           }
         }
       }
   if(flag){
     alert("请选中一条记录");
     return false;
   }else{
      if(confirm("确定取消审核全部?")){
             location="/admin/managerNew.do?method=assNewsByStrs&str="+temp;
      }
   }
  }
</script>
</head>

<body>

<%   NewsDAO newdao=new NewsDAO();
    AdminQxDAO qxdao=new AdminQxDAO();
Admin admin=(Admin)request.getSession().getAttribute("admin");		   
int pagesize=10;
int currpage=1;
//总的页数
int totalPage = 1;
//总共有的记录数
int totalCount = 1;
List newslist=null;
String channelid=request.getParameter("channelid");
String option = "";
if(channelid != null){
	option = "&channelid="+channelid;
}

if (admin.getRole().getId() == 3 || admin.getRole().getId() == 5 ) 
    {       if(channelid==null||channelid.equals("null"))
		    {
    		totalCount=newdao.count(News.class,"where isAss<>'2'");
		    }
            else
            {
        		totalCount=newdao.count(News.class,"where channelid='"+channelid+"'and isAss<>'2'");
            }
    }
else
    {
   if(channelid==null||channelid.equals("null"))
		    {
		totalCount=newdao.count(News.class,"where admin.adminId='"+admin.getAdminId()+"' and isAss<>'2'");
		    }
	      else
	      {
	  		totalCount=newdao.count(News.class,"where admin.adminId='"+admin.getAdminId()+"' and channelid='"+channelid+"' and isAss<>'2'");
	      }
	}
//得到总的页数
if(totalCount%pagesize==0){
	totalPage = totalCount/pagesize;
}else{
	totalPage = totalCount/pagesize+1;
}
//判断是否是传过来页数
if(request.getParameter("currpage") != null){
   currpage = Integer.parseInt(request.getParameter("currpage"));
   if(currpage<1){
     currpage=1;
    }
   if(currpage >totalPage){
     currpage = totalPage;
   }
} 
if (admin.getRole().getId() == 3 || admin.getRole().getId() == 5 ) {
if(channelid==null||channelid.equals("null"))
		    {
			newslist=newdao.findPageByHql("where isAss<>'2' order by addDate desc,newId desc",currpage,pagesize);
		    }
            else
            {
            	newslist=newdao.findPageByHql("where channelid='"+channelid+"' and isAss<>'2' order by addDate desc,newId desc",currpage,pagesize);
            }
    }
else
    {
   if(channelid==null||channelid.equals("null"))
		    {
			newslist=newdao.findPageByHql("where admin.adminId='"+admin.getAdminId()+"' and isAss<>'2' order by addDate desc,newId desc",currpage,pagesize);
		    }
	      else
	      {
	      	newslist=newdao.findPageByHql("where admin.adminId='"+admin.getAdminId()+"' and channelid='"+channelid+"' and isAss<>'2' order by addDate desc,newId desc",currpage,pagesize);
	      }
	}
%>

    
      <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
      <tr>
        <td width="4%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">选择</div></td>
        <td width="25%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">标题</div></td>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">所属栏目</div></td>
        <td width="10%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">发布时间</div></td>
        <td width="6%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">作者</div></td>
        <td width="7%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">状态</div></td>
        <td width="25%" height="25" background="images/tab_14.gif" class="STYLE1"><div align="center" class="STYLE1">编辑</div></td>
        </tr>
        <%
			for(int i = 0 ; i < newslist.size(); i++){
				News news = (News)newslist.get(i);
		%>
		<tr>
          <td width="4%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
		 <input type="checkbox" name="MyCheckBox" id="MyCheckBox" value="<%=news.getNewId() %>" />
		  </td>
          <td width="25%" height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px" class="STYLE1">
		  <%
	
			if(news.getTitle().length()>16){										        	
			   out.print(news.getTitle().substring(0,16)+"...");
			 }else{
				out.print(news.getTitle());
			 }
		   %>
		  
		  </td>
 		  <td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"><%=news.getChannelid().getName()%></td>
          <td width="10%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"><%=news.getAddDate().toString().substring(0,10) %></td>
          <%Admin admin2=news.getAdmin(); 
          %>
          <td width="6%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1"><%=admin2.getAdminName()%></td>
          <td width="7%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
		  <%
			String isAss = news.getIsAss();
			if(isAss .equals("0"))
			{
				if(admins.getIsAss()==null || admins.getIsAss().equals("0"))
				{
					out.print("未审核");
				}
				else{
				%>
				<a href="<%=request.getContextPath()%>/admin/managerNew.do?method=assById&newsid=<%=news.getNewId() %><%=option %>"><font color="red">未审核</font></a>
				<%
				}
			} else
			{
				if(admins.getIsAss()==null || admins.getIsAss().equals("0"))
				{
					out.print("已审核");
				}
				else{
				%>
				<a href="<%=request.getContextPath()%>/admin/managerNew.do?method=assByIds&newsid=<%=news.getNewId() %><%=option %>">已审核</a>
				<%
				}
				
			}
		  %>
		  </td>
          <td width="25%" height="25" align="center" valign="middle" bgcolor="#FFFFFF" class="STYLE1">
		  <a href="/info.jsp?channelid=<%=news.getChannelid().getChannelId() %>&newsid=<%=news.getNewId() %>" target="_blank">预览</a>&nbsp;
		  <a href="upNews.jsp?newsid=<%=news.getNewId() %><%=option %>" target="_parent">修改</a>&nbsp;
		  <a href="<%=request.getContextPath()%>/admin/managerNew.do?method=newRecycle&newsid=<%=news.getNewId() %><%=option %>" onclick="return confirm('确定要把新闻放入回收站？您可以进入回收站还原')">回收站</a>&nbsp;
		  <a href="<%=request.getContextPath()%>/admin/managerNew.do?method=delById&newsid=<%=news.getNewId() %><%=option %>" onclick="return confirm('确定要删除吗？删除之后无法恢复')">删除</a>
		  </td>
        </tr>
		<%
			}
		%>
		
      </table>
	    <table width="98%" border="0" cellspacing="0" cellpadding="0">
	  	<tr>
			 <td height="45" align="left" valign="middle" class="STYLE1">
			 <input type="button" name="selectAlls" id="selectAlls" value="全选" onclick="return selectAll()" />
			 <input type="button" name="noSelectAll" id="noSelectAll" value="反选" onclick="return selectOthers();" />
			<input type="button" name="cancelSelects" id="cancelSelects" value="取消选择" onclick="return cancelSelect();" />
			<input type="button" name="delAlls" id="delAlls" value="删除所选" onclick="return delAllDate();"/>
			</td>
		</tr>
	  </table>
      <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="45" align="center" valign="middle" class="STYLE1">
		  共有［<%=totalCount %>］条 当前是第［<%=currpage %>/<%=totalPage %>］页 [<a href="tree.jsp?channelid=<%=channelid%>&currpage=1" class="page">首页</a>][<a href="tree.jsp?channelid=<%=channelid%>&currpage=<%=currpage-1 %>" class="page">上一页</a>][<a href="tree.jsp?channelid=<%=channelid%>&currpage=<%=currpage+1 %>" class="page">下一页</a>][<a href="tree.jsp?channelid=<%=channelid%>&currpage=<%=totalPage %>" class="page">尾页</a>]
		  到第
            <select name="select" onChange="gopage(this)">
			<%
				for(int i = 0;i<totalPage ; i++)
				{
					out.print("<option value='tree.jsp?channelid="+channelid+"&currpage="+(i+1)+"'>"+(i+1)+"</option>");
				}
			%>
			
            </select>
          页
		 </td>
        </tr>
      </table>
</body>
</html>
<script type="text/javascript">
<!--
var message = "<%=session.getAttribute("message")%>";
if(message!=null && message!="null" && message !=""){
   alert(message);
   message="";
  }
  
 function gopage(selected)
 {
 	window.open(selected.value,"_self");
 }
//-->
</script>
<%
	session.removeAttribute("message");
%>